<?php


namespace App\Command\Changedata;


use App\Web\Model\CaseModel;
use App\Web\Model\RabbitMQ\ResumeUpdate;
use EchoPHP\Console\Command;
use EchoPHP\Facades\Db;
use EchoPHP\Facades\Log;
use EchoPHP\Rabbitmq\Query\QueueConsumer;
use EchoPHP\Rabbitmq\Query\QueueProducer;

class InitResumeEngine extends Command {
    protected $signature = "Changedata:InitResumeEngine";
    protected $description = '初始化简历引擎的数据';

    public function handle() {
//        $oprId = 4;
//        $caseId = 261;
//
//        $resumeIds = [];
//        $sql = 'select userid51job from s_manager where userid51job is not null and cname is not null and cname not like ? and userid51job > ?';
//        $var = ['?%',301809746];
//        $result = Db::connect('jyrpo_oracle')->select($sql, $var, 0, 50000);
//        var_dump(count($result));
//        $resumeIds = array_column($result, 'userid51job');
//        $arr = array_chunk($resumeIds, 100);
//        $caseModel = new CaseModel();
//        foreach ($arr as $ids) {
//            $result = $caseModel->addToCase($oprId, $caseId, $ids);
//        }
//        exit;

//        $result = [];
//        $sql1 = 'select resumeid from RpoResume where status=?';
//        $var1 = ['01'];
//        $result1 = Db::connect()->select($sql1, $var1);
//        $result1 = array_column($result1, 'resumeid');
//        $result = array_merge($result, $result1);

//        $sql1 = 'select resumeid from CaseResume where status=?';
//        $var1 = ['01'];
//        $result1 = Db::connect()->select($sql1, $var1);
//        $result1 = array_column($result1, 'resumeid');
//        $result = array_merge($result, $result1);
//
//        $sql1 = 'select resumeid from ResumeDownload';
//        $var1 = [];
//        $result1 = Db::connect()->select($sql1, $var1);
//        $result1 = array_column($result1, 'resumeid');
//        $result = array_merge($result, $result1);
//
        //        foreach ($result as $item) {
//            fwrite($handle,$item."\r\n");
//        }
//        exit;
//        $produce = new QueueProducer('resumeupdate');
        $file = ROOT_PATH . '/app/Command/Changedata/InitResumeEngine_resumeid.txt';
        $handle = fopen($file, 'r');
        //查看总数
        $resumeIds = [];
        while ($line = fgets($handle)) {
            $resumeIds[] = intval(trim($line));
        }
        $resumeIds = array_unique($resumeIds);
        $count = count($resumeIds);
        echo '总数:' . $count . "\r\n";
        $resultArr = array_chunk($resumeIds, 100);

        $resumeUpdate = new ResumeUpdate();
        $flagNum = 1;
        foreach ($resultArr as $item) {
            $updateResult = $resumeUpdate->addToQueue($item);
            echo "批次:" . $flagNum . " 发送" . count($item) . "条数";
            echo "\r\n";
            $flagNum++;
        }
        echo '执行完毕';
    }
}